<template>
  <div>
    <el-card>
      <!-- 借款用户 -->
      <div class="Banner">
        <el-row :gutter="24" >
           <!-- 搜索框 -->
          <el-col :span="20">
            <el-col :span="5">
            <el-input
                  type="text" icon="el-icon-search"
                  placeholder="搜索姓名" 
                  v-model="getByName"> 
            </el-input>
            </el-col>
            <el-col :span="5">
            <el-input
                  type="text"
                  placeholder="搜索手机/用户名" 
                  v-model="getByPhone" >
            </el-input>
            </el-col>
           <!-- 下拉选项 -->
           <el-col :span="4">
            <template>
              <el-select v-model="userState" placeholder="全部状态">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </template>
            </el-col>
            <!-- 搜索按钮 -->
           <el-col :span="5" :offset="0">
            <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
           </el-col>
         </el-col>
        <!-- 右上角新增用户链接 -->
        <el-col :span="4">
          <el-button type="primary" @click="addBanner">
            新增用户
          </el-button>
        </el-col>
        </el-row>
      </div>

      <br />

      <!-- 表头数据绑定 -->
      <TableComponent
        :cols="cols"
        :tableData="tableData"
        :total="total"
        @requestData="requestData"
      >
        <!-- 操作列 -->
        <template slot-scope="scope" slot="operating">
          <el-button @click="onView(scope)">查看资料</el-button>
        </template>
        <!-- 引入表格组件 -->
      </TableComponent>
    </el-card>
  </div>
</template>

<script>
import TableComponent from "../../components/basic/TableComponent.vue";
import { getLoanUserFrom } from "../../http/member";//引入接口

export default {
  name: "Member2",
  components: {
    TableComponent,
  },
  data() {
    return {
      //表头
      cols: {
        id: "用户编号",
        name: "姓名/公司名称",
        phone: "手机/用户名",
        email: "借款人邮箱",
        lockStatus: "锁定状态",
        regTime: "注册时间",
        loginTime: "最近登录",
        resource: "用户来源",
      },
       options: [{
          value: '选项1',
          label: '锁定'
        }, 
         {
          value: '选项2',
          label: '正常'
        }],
      //表单里的内容
      tableData: [],
      total: 0,//总计
      getByName:'',
      getByPhone:'',
      userState:"",
      page: "",
      limit:""
    };
  },
  methods: {
    addBanner() {
      //新增用户
      this.$router.push("/member");
    },
    search() {
      //搜索
      this.requestData(1,5,{
        name: this.getByName,
        phone: this.getByPhone,
        lockStatus:this.userState,
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    requestData(page, limit,requerment) {
      this.page = page;
      this.limit = limit;
      requerment = requerment || {
        name: this.getByName,
        phone: this.getByPhone,
        lockStatus:this.userState,
      }
      getLoanUserFrom(page, limit,requerment)
        .then((res) => {
          console.log(res);
          if (res.data.code == 20000) {
            this.total = res.data.data.counts;//总数据
            this.tableData = res.data.data.result;//表格数据
          }
          console.log(res.data.message);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    onView(scope) {
      this.$router.push(`/member/m2/m4/${scope.data.data.id}`);
    },
  },
  beforeMount() {
    this.requestData(1, 5);
  },
};
</script>

<style scoped>
</style>